home *** CD-ROM | disk | FTP | other *** search
-
- This file contains the two files used for the "sieve" C++ benchmark.
- You'll have to separate them. They are
-
- sv_cpp.h The include file used to re-implement all the
- arithmetic operators.
- sieve.cpp The sieve program, slightly modified to:
- a) reference the "sv_cpp.h" file
- b) change the number of loops from 10 to 100.
-
-
- -------------------- Beginning of sv_cpp.h --------------------
-
- /* SV_CPP.H - new "int" class for the seive benchmark for C++ */
-
- class INT {
- int val;
- public:
- INT( int i ) { val = i; }
- INT(){}
- /* ~INT(){} */
- int operator= (int t2);
- int operator+ (int t2);
- int operator- (int t2);
- int operator+= (int t2);
- int operator++ ();
- int operator<= (int t2);
-
- operator int();
-
- };
-
- /* Include the following statement to prevent inline substitution of
- code implementing arithmetic operations; enclose it in comments
- to make that code inline. */
- #define inline
-
- /* Likewise, include the following in comments to prevent declaring the
- second term of each operator as a register variable */
- /* #define register */
-
- inline int INT :: operator= ( register int t2 )
- {
- return( val = t2 );
- }
-
- inline int INT :: operator+ ( register int t2 )
- {
- return( val + t2 );
- }
-
- inline int INT :: operator- ( register int t2 )
- {
- return( val - t2 );
- }
-
- inline int INT :: operator+= ( register int t2 )
- {
- return( val += t2 );
- }
-
- inline int INT :: operator++ ( )
- {
- return( val++ );
- }
-
- inline int INT :: operator<= ( register int t2 )
- {
- return( val <= t2 );
- }
-
- inline int INT :: operator int ( )
- {
- return( val );
- }
-
-
- /* Now for the trick.. */
- #define int INT
-
- -------------------- End of sv_cpp.h --------------------
-
-
- -------------------- Beginning of sieve.cpp --------------------
-
- /*
- Eratosthenes Sieve Prime Number Program in from BYTE January 1983
- */
-
- #include "sv_cpp.h"
-
- #define TRUE 1
- #define FALSE 0
- #define size 8190
-
- char flags [size + 1];
- main()
- {
- int i, prime, k, count, iter;
-
- printf ("100 iterations\n");
- for (iter = 1; iter <= 100; iter++) /* do program 100 times */
- {
- count = 0; /* prime counter */
- for (i = 0; i <= size; i++) /* set all flags true */
- flags [i] = TRUE;
- for (i = 0; i <= size; i++)
- {
- if (flags [i]) /* found a prime */
- {
- prime = i + i + 3; /* twice index + 3 */
- /* printf ("\n%d", prime); */
- for (k = i + prime; k <= size; k+= prime)
- flags [k] = FALSE; /* kill all multiple */
- count++; /* primes found */
- }
- }
- }
- printf ("\007%d primes.\n", count); /* primes found on 100th pass */
- }
-
- -------------------- End of sieve.cpp --------------------
-